<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"
%><%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"
%><%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"
%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%>
<head>
    <title><fmt:message key="contentlet" /></title>
</head>
<body>
	<script language="JavaScript">
	<!--
		dojo.require("dojo.data.ItemFileReadStore");
		dojo.addOnLoad(function() {
			dojo.connect(dojo.byId('createLink'), "click", function(evt){
				var inode = dijit.byId('structureInode').value;
				if(null != inode && inode != ''){
					this.href = this.href + '?contentlet.structureInode=' + inode;
				} else {
					dojo.stopEvent(evt); //Stop Event Bubbling, show some tips.
				}
			});

		});

	//-->
	</script>
    <h1><fmt:message key="contentlet" /></h1>
    <div class="buttons">
       <c:url var="createUrl" value="/domain/contentlet/createForm" />
	   <c:url var="structureSearchFields" value="/domain/contentlet/search" />
       <a href="${createUrl}" id="createLink"><span><fmt:message key="label.link.create" /></span></a>
    </div>
	<div>
		<select name="structureInode" id="structureInode">
		</select>
        <script type="text/javascript">
            Spring.addDecoration(new Spring.ElementDecoration({
                elementId : "structureInode",
                widgetType : "dijit.form.FilteringSelect",
                widgetAttrs : {
					value: '${structure.inode}',
					store: new dojo.data.ItemFileReadStore({data: ${structuresData}}),
					labelAttr: "name",
					labelType: "html",
					onChange: function(value) {
						Spring.remoting.getResource('${structureSearchFields}', 
							{'structureInode': value, decorator: "none"});					
					},
                    required : true
                }
            }));
        </script>
		
	</div>
	<jsp:include page="/WEB-INF/views/domain/contentlet/searchResult.jsp" flush="true">
		<jsp:param name="includeBody" value="true" />
	</jsp:include>
</body>
